package com.yz.group1.group_1.controller;
import com.yz.group1.group_1.entity.UserAccount;
import com.yz.group1.group_1.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;

@CrossOrigin
@RestController
@RequestMapping("/userAccount")
public class UserAccountController {

    @Autowired
    private UserAccountService userAccountService;

    @PostMapping("/login")
    public boolean login(@RequestBody UserAccount userAccount) {
        return userAccountService.login(userAccount.getUsername(), userAccount.getPassword());
    }

    @PostMapping("/register")
    public boolean register(@RequestBody UserAccount userAccount) {
        return userAccountService.register(userAccount);
    }

    @GetMapping("/info/{username}")
    public UserAccount getInfo(@PathVariable String username) {
        return userAccountService.getByUsername(username);
    }

    @PostMapping("/update")
    public boolean update(@RequestBody UserAccount userAccount) {
        userAccount.setUpdatedAt(new Date().toString());
        return userAccountService.updateById(userAccount);
    }
}